#!/bin/bash

# Slackware build script for asteroidsinfinity

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=asteroidsinfinity
VERSION=${VERSION:-1.2}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

ARCH=noarch

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

SRCNAM="AsteroidsInfinity"

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SRCNAM
unzip $CWD/$SRCNAM$VERSION.zip
cd $SRCNAM
chown -R root:root .
find -L .  -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
        \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+

mkdir -p \
  $PKG/usr/share/games/$PRGNAM \
  $PKG/usr/games \
  $PKG/usr/doc/$PRGNAM-$VERSION \
  $PKG/usr/share/applications \
  $PKG/usr/share/pixmaps

cp -a $SRCNAM.py font/ sounds/ icon.png $PKG/usr/share/games/$PRGNAM
install -oroot -groot -m0755 $CWD/$PRGNAM.sh $PKG/usr/games/$PRGNAM
cp -a *.txt $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

ln -s ../games/$PRGNAM/icon.png $PKG/usr/share/pixmaps/$PRGNAM.png

# .desktop written for this SlackBuild.
cat $CWD/$PRGNAM.desktop > $PKG/usr/share/applications/$PRGNAM.desktop

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
